package com.lzx.resumeweb.api;

import com.lzx.resumebase.model.Photo;
import com.lzx.resumebase.model.Result;
import com.lzx.resumebase.util.ResultUtil;
import com.lzx.resumeservice.service.PhotoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PhotoApi
 * @Author 刘正星
 * @Date 2021/6/16 上午9:37
 * @Description
 */
@RestController
@Slf4j
@RequestMapping("/photo")
public class PhotoApi {

    @Autowired
    private PhotoService photoService;

    @GetMapping("/list")
    public Result list(){

        return ResultUtil.success(photoService.list(null));

    }

    @PostMapping("/save")
    public Result save(@RequestBody Photo photo){

        if (photo == null) {
            log.error("save photo is null!");
            return ResultUtil.paramError();
        }

        return ResultUtil.success(photoService.saveOrUpdate(photo));

    }

    @DeleteMapping("/del/{id}")
    public Result del(@PathVariable("id")Integer id){
        if (null==id){
            log.error("del id is null");
            return ResultUtil.paramError();
        }
        return ResultUtil.success(photoService.removeById(id));
    }

}
